package com.war.controller.dataChart;

import com.war.dao.outOfStorage.ProductOutDao;
import com.war.dao.stock.DamagesDao;
import com.war.dao.stock.TransferDao;
import com.war.dao.warehousing.PurchaseDao;
import com.war.pojo.outofstorage.ProductOut;
import com.war.pojo.stock.DamagesInfo;
import com.war.pojo.stock.TransferInfo;
import com.war.pojo.warehousing.PurchaseInfo;
import com.war.service.safeManage.UserService;
import com.war.service.stock.DamagesInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/chart")
public class ChartController {

    //入库报表路由
    @RequestMapping("")
    public String in_num(){
        return "dataChart/chart";
    }


    //入库数量报表
    @Autowired(required = false)
    PurchaseDao purchaseDao;
    @RequestMapping("/in_num_data")
    @ResponseBody
    public HashMap<String,Object> in_num_data(){
        HashMap<String,Object> map = new HashMap<>();
        List<PurchaseInfo> purchaseInfoList = purchaseDao.in_num_data();
        List<Object> x = new ArrayList<>();
        List<Object> y = new ArrayList<>();
        for(int i=0;i<purchaseInfoList.size();i++){
            x.add(purchaseInfoList.get(i).getProductName());
            y.add(purchaseInfoList.get(i).getStorageNum());
        }
        map.put("x",x);
        map.put("y",y);
        return map;
    }

    //报表数据
    @Autowired(required = false)
    ProductOutDao productOutDao;

    @RequestMapping("/out_num_data")
    @ResponseBody
    public HashMap<String,Object> out_num_data(){
        HashMap<String,Object> map = new HashMap<>();
        List<ProductOut> productOutList = productOutDao.select();
        List<Object> x = new ArrayList<>();
        List<Object> y = new ArrayList<>();
        for(int i=0;i<productOutList.size();i++){
            x.add(productOutList.get(i).getProductName());
            y.add(productOutList.get(i).getOutAmount());
        }
        map.put("x",x);
        map.put("y",y);
        return map;
    }



    //报表数据
    @Autowired(required = false)
    DamagesDao damagesDao;

    @RequestMapping("/damages_num_data")
    @ResponseBody
    public HashMap<String,Object> damages_num_data(){
        HashMap<String,Object> map = new HashMap<>();
        List<DamagesInfo> damagesInfoList = damagesDao.damages_num_data();
        List<Object> x = new ArrayList<>();
        List<Object> y = new ArrayList<>();
        for(int i=0;i<damagesInfoList.size();i++){
            x.add(damagesInfoList.get(i).getProduct_name());
            y.add(damagesInfoList.get(i).getDamages_num());
        }
        map.put("x",x);
        map.put("y",y);
        return map;
    }


    //报表数据
    @Autowired(required = false)
    TransferDao transferDao;

    @RequestMapping("/transfer_num_data")
    @ResponseBody
    public HashMap<String,Object> transfer_num_data(){
        HashMap<String,Object> map = new HashMap<>();
        List<TransferInfo> transferInfoList = transferDao.transfer_num_data();
        List<Object> x = new ArrayList<>();
        List<Object> y = new ArrayList<>();
        for(int i=0;i<transferInfoList.size();i++){
            x.add(transferInfoList.get(i).getProduct_name());
            y.add(transferInfoList.get(i).getOut_num());
        }
        map.put("x",x);
        map.put("y",y);
        return map;
    }

}

